<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<link id="target" rel="stylesheet" href="old.css">
</head>
<body>
<script>
description('This tests that ownerNode of orphan sheet is null.');

jsTestIsAsync = true;

window.onload = function()
{
    oldSheet = target.sheet;
    target.setAttribute("href", "new.css");
    
    function waitAndTest() {
        if (0 <= target.sheet.href.indexOf("old.css"))
            return window.setTimeout(waitAndTest, 0);
        shouldBeNull("oldSheet.ownerNode");
        if (oldSheet.ownerNode)
            return finishJSTest();
        // We need to exercise cached case as well, which can be executed with a reload.
        if (0 <= window.location.toString().indexOf("?reloaded"))
            return finishJSTest();
        window.location = window.location.toString() + "?reloaded";
    };

    window.setTimeout(waitAndTest, 0);
};

</script>
</body>
</html>
